package com.fgw.admin.web;

import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.fgw.admin.dto.ResultInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;

import com.fgw.admin.entity.Industry;
import com.fgw.admin.service.IIndustryService;
import com.fgw.admin.vo.IndustryVo;

/**
 * 所属行业/国标行业 前端控制器
 *
 * @author system
 * @date 2020-11-10 21:29:38
 */
@Controller
@RequestMapping("/industry")
public class IndustryController {
    @Resource
    private IIndustryService iIndustryService;

    @RequestMapping("/*")
    public void toHtml(){

    }

    @RequestMapping("/listData")
    @RequiresPermissions("industry:view")
    @ResponseBody
    public ResultInfo<List<Industry>> listData(Industry industry, Integer page, Integer limit){
        EntityWrapper<Industry> wrapper = new EntityWrapper<>(industry);
        Page<Industry> pageObj = iIndustryService.selectPage(new Page<>(page,limit), wrapper);
        return new ResultInfo<>(pageObj.getRecords(), pageObj.getTotal());
    }

    @RequestMapping("/add")
    @RequiresPermissions("industry:add")
    @ResponseBody
    public ResultInfo<Boolean> add(Industry industry){
        boolean b = iIndustryService.insert(industry);
        return new ResultInfo<>(b);
    }

    @RequestMapping("/delBatch")
    @RequiresPermissions("industry:del")
    @ResponseBody
    public ResultInfo<Boolean> delBatch(Integer[] idArr){
        boolean b = iIndustryService.deleteBatchIds(Arrays.asList(idArr));
        return new ResultInfo<>(b);
    }

    @RequestMapping("/edit")
    @RequiresPermissions("industry:edit")
    @ResponseBody
    public ResultInfo<Boolean> edit(Industry industry){
        boolean b = iIndustryService.updateById(industry);
        return new ResultInfo<>(b);
    }
    
    @RequestMapping(value="/getTree",method=RequestMethod.POST)
    @ResponseBody
    public ResultInfo<List<IndustryVo>> getIndustryTree(){
    	
    	List<IndustryVo> list = iIndustryService.getIndustryTree(0);
    	
    	return new ResultInfo<>(list);
    	
    	
    }
    
    

}
